package com.example.diancai.controller;


import com.example.diancai.entity.GameUser;
import com.example.diancai.service.GameUserService;
import com.example.diancai.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/game")
public class GameController {

    @Autowired
    private GameUserService gameUserService;

    @PostMapping("/startGameUser/{gameType}")
    public GameUser startGameUser(@PathVariable String gameType) {
        return gameUserService.startGameUser(gameType);
    }

    @GetMapping("/getLastGameUser/{gameType}")
    public GameUser getLastGameUser(@PathVariable String gameType) {
        return gameUserService.getLastGameUser(AuthUtil.getCurrPlayerId(), gameType);
    }

    @PostMapping("/updateGameUser/{id}")
    public GameUser updateGameUser(@PathVariable Integer id,
                                    @RequestBody GameUser gameUser) {
        gameUser.setId(id);
        return gameUserService.updateGameUser(gameUser);

    }

}
